package com.h3bpm.kumhosunny.knowledge.controller;

import OThinker.H3.Controller.ControllerBase;
import com.alibaba.fastjson.JSONObject;
import com.h3bpm.kumhosunny.common.utils.SqlUtil;
import data.DataRow;
import data.DataTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: development
 * @Description: 描述
 *
 * @author WJQ
 * @version V1.0
 * @Date 2019-10-16 
 */
@Controller
@RequestMapping("/Portal/knowledge/developmen")
public class DevelopmentController extends ControllerBase {

    private static Logger log = LoggerFactory.getLogger(DevelopmentController.class);
    @RequestMapping("/getBoList")
    @ResponseBody
    public JSONObject getBoList(String clientData ,String state ){
        log.info("移动端知识接口==================clientData="+clientData);
        JSONObject result= new JSONObject();
        try {
        String userId =  getUserValidator().getUser().getObjectID();
        String parentId =  getUserValidator().getUser().getParentID();
        String sql="SELECT i.documentName,i.trade,i.brandName,o.ObjectId FROM i_knowledge i, ot_instancecontext o WHERE  nowState != 1 and i.ObjectId=o.bizObjectId ORDER BY i.CreatedTime DESC";
        if(clientData != null &&  !"".equals(clientData)){
            sql= "SELECT i.documentName,i.trade,i.brandName,o.ObjectId ,o.ObjectId FROM (SELECT documentName,trade,brandName,ObjectId FROM i_knowledge WHERE  nowState != 1 and  documentName LIKE '%"+clientData+"%' OR trade like '%"+clientData+"%' or brandName LIKE '%"+clientData+"%') i LEFT JOIN ot_instancecontext o  ON i.ObjectId=o.bizObjectId ORDER BY i.CreatedTime DESC";

        }
        DataTable table = null;
        table = SqlUtil.doQuery(sql);
        List<Map<String ,String >> list =new ArrayList<Map<String ,String > >();
        if(table!=null && table.getEntityRows()!=null && table.getEntityRows().size()>0){
            for( DataRow dataRow :  table.getEntityRows()) {
                Map<String, String> customerMap = new HashMap<String, String>(16);
                String documentName=dataRow.getString("documentName");
                String brandName=dataRow.getString("brandName");
                String trades=dataRow.getString("trade");
                String objectId=dataRow.getString("ObjectId");
                customerMap.put("documentName",documentName);
                customerMap.put("brandName",brandName);
                customerMap.put("trade",trades);
                customerMap.put("ObjectId",objectId);
                list.add(customerMap);
            }
          }
            result.put("data",list);
            result.put("status","200");
        } catch (Exception e) {
            result.put("status","500");
            e.printStackTrace();
            }

        return result;

    }
    @Override
    public String getFunctionCode() {
        return null;
    }
}
